<template>
	<jb-crud-page ref="pageRef" searchUrl="/VDBResource/list" :conditions-align="'start'" :editComponent="ModelEdit"
		:searchConditions="pageConditions">
		<template #conditions-form>
			<jb-input v-model:value="pageConditions.keywords" placeholder="请输入关键词搜索" style="width: 200px"></jb-input>
		</template>
		<template #opt>
			<jb-btn type="primary" secondary @click="pageRef.showEditModal('添加资源')">添加资源</jb-btn>
		</template>

		<template #default="{list,tableStartIndex}">
			<jb-table :data="list" :start-index="tableStartIndex">
				<jb-column type="seq" title="序号" width="60" fixed="left"></jb-column>
				<jb-column field="name" title="资源名称" min-width="160" fixed="left"></jb-column>
				<jb-column field="modelName" title="资源类型" min-width="160"></jb-column>
				<jb-column field="embeddingName" title="embedding" min-width="160"></jb-column>
				<jb-column field="url" title="url" min-width="160">
				</jb-column>
				<jb-column field="databaseName" title="数据库名" min-width="160">
				</jb-column>
				<jb-column field="createTime" title="创建时间" min-width="160"></jb-column>
				<jb-column field="enable" title="是否启用" min-width="160" fixed="right">
					<template #default="{ row }">
						<jb-switch v-model:value="row.enable" :url="`/VDBResource/toggleEnable/${row.id}`"
							@update:value="pageRef.loadData()"></jb-switch>
					</template>
				</jb-column>

				<jb-column title="操作" width="120" fixed="right">
					<template #default="{ row }">
						<jb-btn class="mx-8px" tip-text="编辑资源" secondary circle type="warning" :icon="Icons.EDIT"
							@click="pageRef.showEditModal('编辑资源',{id:row.id})"></jb-btn>

						<jb-btn class="mx-8px" tip-text="删除资源" secondary circle type="error" :icon="Icons.DELETE"
							:confirmText="'确认删除该资源？'" :url="`/VDBResource/del/${row.id}`"
							@success="pageRef.loadData()"></jb-btn>
					</template>

				</jb-column>

			</jb-table>
		</template>
	</jb-crud-page>
</template>

<script setup>
	import {
		h,
		onMounted,
		ref
	} from 'vue'
	import {
		NButton,
		NSpace,
		NTag,
		useMessage
	} from 'naive-ui'
	import ModelEdit from './cpns/model-edit.vue'
	import {
		useResetableData
	} from '@/hooks/common/use-resetable-data'
	import {
		Icons
	} from '@/constants'
	import {
		JBoltApi
	} from "@/service/request/index.js";

	const pageRef = ref(null)
	const pageConditions = useResetableData({
		keywords: ''
	})

	const vdbTypeList = ref([])
	onMounted(() => {
		JBoltApi.tryGet('/VDB/list').then(res => {
			vdbTypeList.value = res.data
		}).catch(error => {
            console.error(error)
        })
	})
</script>

<style scoped>

</style>